package com.project.slsx.adapter;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.project.slsx.Constant.Constans;
import com.project.slsx.R;
import com.project.slsx.bean.OrderListBean;
import com.project.slsx.utils.GlideUtils;
import com.project.slsx.utils.ParamsUtils;

import java.util.List;

public class OrderList2Adapter extends BaseQuickAdapter<OrderListBean.ResultBean.GoodsBean, BaseViewHolder> {

    private OnItemClickListener2 onItemClickListener2;

    public OrderList2Adapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(final BaseViewHolder holder, final OrderListBean.ResultBean.GoodsBean item) {
        holder.setText(R.id.tv_goods_name, item.getGoods_title());
        holder.setText(R.id.tv_goods_unit_price, item.getGoods_unit_price());
        holder.setText(R.id.tv_goods_price, item.getGoods_price());
        holder.setText(R.id.tv_goods_no, item.getGoods_num());
        ImageView ivGoods = holder.getView(R.id.iv_order);
        RequestOptions option = GlideUtils.getOption();
        Glide.with(mContext)
                .load(item.getThumb())
                .apply(option)
                .into(ivGoods);

//        //再来一单
//        Button btnMore = holder.getView(R.id.btn_order_more);
//        btnMore.setOnClickListener(v -> {
//            Log.i(TAG, "convert: " + holder.getLayoutPosition());
//        });
//
//        holder.getView(R.id.btn_order_repay).setOnClickListener(v -> {
//            Log.i(TAG, "convert: " + holder.getLayoutPosition());
//        });

    }

    /**
     * 取消
     *
     * @param item
     */
    private void doCancelGoods(OrderListBean.ResultBean.GoodsBean item) {
        HttpParams orderdeleteParams = ParamsUtils.getOrderdeleteParams();
        orderdeleteParams.put("order_id", item.getId());
        orderdeleteParams.put("id", item.getGoods_id());
        orderdeleteParams.put("number", item.getGoods_num());

        OkGo.<String>post(Constans.BASEURL).tag("orderdelete").params(orderdeleteParams).execute(new StringCallback() {
            @Override
            public void onStart(Request<String, ? extends Request> request) {
                super.onStart(request);

            }

            @Override
            public void onSuccess(Response<String> response) {
                Log.i(TAG, "onSuccess: " + response.body());
            }

            @Override
            public void onError(Response<String> response) {
                super.onError(response);
                Log.i(TAG, "onError: " + response.body());
            }

            @Override
            public void onFinish() {
                super.onFinish();

            }
        });
    }

    public interface OnItemClickListener2 {
        void onInnderItemClick(int position);
    }

    public void setOnItemClickListener2(OnItemClickListener2 onItemClickListener2) {
        this.onItemClickListener2 = onItemClickListener2;
    }
}
